<template>
  <div class="auth-page">
    <div class="container page">
      <div class="row">
        <div class="col-md-6 offset-md-3 col-xs-12">
          <h1 class="text-xs-center">Sign in</h1>
          <p class="text-xs-center">
            <a href="">welcome to visit BlogParty</a>
          </p>

          <ul class="error-messages">
            <template v-for="(messes, title, index) in errors">
              <li :key="index" v-for="mess in messes">{{ title }}{{ mess }}</li>
            </template>
          </ul>

          <form @submit.prevent="onLogin">
            <fieldset class="form-group">
              <input
                class="form-control form-control-lg"
                type="text"
                placeholder="Your Name"
                v-model="user.username"
              />
            </fieldset>
            <fieldset class="form-group">
              <input
                class="form-control form-control-lg"
                type="email"
                placeholder="Email"
                v-model="user.email"
                required="true"
              />
            </fieldset>
            <fieldset class="form-group">
              <input
                class="form-control form-control-lg"
                type="password"
                placeholder="Password"
                v-model="user.password"
                required="true"
              />
            </fieldset>
            <button class="btn btn-lg btn-primary pull-xs-right">
              Sign in
            </button>
          </form>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { regist } from "@/api/user.js";
export default {
  data() {
    return {
      user: {
        username: "",
        email: "",
        password: "",
      },
      errors: {},
    };
  },

  components: {},

  methods: {
    async onLogin() {
      try {
        const { data } = await regist({ user: this.user });
        this.$router.push("/login");

        console.log(data);
      } catch (error) {
        console.log(error);
        console.dir(error);
        this.errors = error.response.data.errors;
      }
    },
  },
};
</script>

<style scoped></style>
